package com.shuqi.activity.adapter;

import java.text.SimpleDateFormat;
import java.util.List;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.shuqi.controller.R;
import com.shuqi.model.bean.FeedBackInfo;

/**
 * 意见反馈Adapter
 * 
 * @author zhuchen
 * 
 */
public class FeedBackAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private SimpleDateFormat format;
    private List<FeedBackInfo> list;

    public void setList(List<FeedBackInfo> list) {
        this.list = list;
    }

    public FeedBackAdapter(Context context) {
        this.inflater = LayoutInflater.from(context);
        format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    }

    public int getCount() {
        if (list != null) {
            return list.size();
        } else {
            return 0;
        }

    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = null;
        if (convertView != null) {
            view = convertView;
        } else {
            view = inflater.inflate(R.layout.item_feedback_list, parent, false);
        }

        Holder holder = (Holder) view.getTag();
        if (holder == null) {
            holder = new Holder();
            holder.item_feedback_content = (TextView) view.findViewById(R.id.item_feedback_content);
            holder.item_feedback_time = (TextView) view.findViewById(R.id.item_feedback_time);
            holder.item_feedback_reply = (TextView) view.findViewById(R.id.item_feedback_reply);
            holder.item_title = (LinearLayout) view.findViewById(R.id.item_title);
            view.setTag(holder);
        }
        FeedBackInfo info = list.get(position);
        if (info != null) {
            // 赋值
            holder.item_feedback_content.setText(info.getContent());
            if (TextUtils.isEmpty(info.getReply())) {
                holder.item_feedback_reply.setVisibility(View.GONE);
                holder.item_title.setVisibility(View.GONE);
            } else {
                holder.item_title.setVisibility(View.VISIBLE);
                holder.item_feedback_reply.setText(info.getReply());
                holder.item_feedback_reply.setVisibility(View.VISIBLE);
            }
            holder.item_feedback_time.setText(format.format(Long.valueOf(info.getTime())));
        }
        return view;
    }

    /** 控件 */
    public static class Holder {
        private TextView item_feedback_time;// 提问时间
        private TextView item_feedback_content;// 提问内容
        private TextView item_feedback_reply;// 回复内容
        private LinearLayout item_title;
    }

}
